﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SDATA;

namespace SABI
{
    public partial class frm0001G : Form
    {
        public frm0001G()
        {
            InitializeComponent();
        }

        private void frm0001G_Load(object sender, EventArgs e)
        {

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            (Application.OpenForms["frmHome"] as frmHOME).CloseTab(this);
        }

        private void frm0001G_Shown(object sender, EventArgs e)
        {
            loadDATA();
        }

        void loadDATA()
        {
            chkIsNegativeStock.Checked = FRM.IsNegativeStock;
            chkIsCommission.Checked = FRM.IsCommission;
            chkIsLockSalePrice.Checked = FRM.IsLockSalePrice;
            chkIsTestSalePrice.Checked = FRM.IsTestSalePrice;
            chkIsDiscount.Checked = FRM.IsDiscount;
            chkIsNegativeCash.Checked = FRM.IsNegativeCash;
            chkIsAutoSourceNo.Checked = FRM.IsAutoSourceNo;
            chkApprove.Checked = FRM.Approve;
            chkUsePriceSheet.Checked = FRM.UsePriceSheet;
            chkOverDue.Checked = FRM.IsOverDue;            
            chkOverDueIsSave.Checked = FRM.IsOverDueSave;
            chkOverDueIsShow.Checked = FRM.IsOverDueShow;
            chkIsPromotion.Checked = FRM.IsPromotion;
            if (!FRM.IsOverDue) { chkOverDue_CheckedChanged(null, null); }
            chkIsAllObjectID.Checked = FRM.IsAllObjectID;
            chkIsAllAccountID.Checked = FRM.IsAllAccountID;
            chkIsAllBankAccountID.Checked = FRM.IsAllBankAccountID;
            chkIsAllInventoryID.Checked = FRM.IsAllInventoryID;
            chkIsAllVoucherTypeID.Checked = FRM.IsAllVoucherTypeID;
        }

        private void chkOverDue_CheckedChanged(object sender, EventArgs e)
        {
            frameOverDue.Enabled = chkOverDue.Checked;
            chkOverDueIsSave.Checked = chkOverDue.Checked;
            chkOverDueIsShow.Checked = chkOverDue.Checked;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            FRM.IsNegativeStock = chkIsNegativeStock.Checked;
            FRM.IsCommission = chkIsCommission.Checked;
            FRM.IsLockSalePrice = chkIsLockSalePrice.Checked;
            FRM.IsTestSalePrice = chkIsTestSalePrice.Checked;
            FRM.IsDiscount = chkIsDiscount.Checked;
            FRM.IsNegativeCash = chkIsNegativeCash.Checked;
            FRM.IsAutoSourceNo = chkIsAutoSourceNo.Checked;
            FRM.Approve = chkApprove.Checked;
            FRM.UsePriceSheet = chkUsePriceSheet.Checked;
            FRM.IsOverDue = chkOverDue.Checked;
            FRM.IsOverDueSave = chkOverDueIsSave.Checked;
            FRM.IsOverDueShow = chkOverDueIsShow.Checked;
            FRM.IsPromotion = chkIsPromotion.Checked;
            FRM.IsAllObjectID = chkIsAllObjectID.Checked;
            FRM.IsAllAccountID = chkIsAllAccountID.Checked;
            FRM.IsAllBankAccountID = chkIsAllBankAccountID.Checked;
            FRM.IsAllInventoryID = chkIsAllInventoryID.Checked;
            FRM.IsAllVoucherTypeID = chkIsAllVoucherTypeID.Checked;

            string sql = "UPDATE tb0000 SET ";
            sql += string.Format("IsNegativeStock='{0}',IsCommission='{1}',IsLockSalePrice='{2}',",FRM.IsNegativeStock?1:0,FRM.IsCommission?1:0,FRM.IsLockSalePrice?1:0);
            sql += string.Format("IsTestSalePrice='{0}',IsDiscount='{1}',IsNegativeCash='{2}',", FRM.IsTestSalePrice ? 1 : 0, FRM.IsDiscount ? 1 : 0, FRM.IsNegativeCash ? 1 : 0);
            sql += string.Format("IsAutoSourceNo='{0}',Approve='{1}',UsePriceSheet='{2}',", FRM.IsAutoSourceNo ? 1 : 0, FRM.Approve ? 1 : 0, FRM.UsePriceSheet ? 1 : 0);
            sql += string.Format("IsOverDue='{0}', IsOverDueSave='{1}', IsOverDueShow='{2}', IsPromotion='{3}',", FRM.IsOverDue ? 1 : 0, FRM.IsOverDueSave ? 1 : 0, FRM.IsOverDueShow ? 1 : 0, FRM.IsPromotion ? 1 : 0);
            sql += string.Format("IsAllObjectID='{0}', IsAllAccountID='{1}', IsAllBankAccountID='{2}',", FRM.IsAllObjectID ? 1 : 0, FRM.IsAllAccountID ? 1 : 0, FRM.IsAllBankAccountID ? 1 : 0);
            sql += string.Format("IsAllInventoryID='{0}', IsAllVoucherTypeID='{1}'", FRM.IsAllInventoryID ? 1 : 0, FRM.IsAllVoucherTypeID ? 1 : 0);
            if (DATA.ExecuteNonQuery(sql, FRM.ConnectString, false))
                SDLL.DLL02.Info("Cập nhật dữ liệu thành công!");
            else
                SDLL.DLL02.Alert("Cập nhật dữ liệu thất bại!");
        }

        
    }
}
